package xyz.soleperson.comands

import org.bukkit.Sound
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import xyz.soleperson.util.RandomSingleton

class CommandMend: CommandExecutor {
    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean {
        if(sender is Player) {
            val player: Player = sender
            val experienceBudget: Int = sender.totalExperience
            player.sendMessage("总经验: $experienceBudget")
            mendSuccess(sender)
            return true
        }

        return false
    }

    fun mendSuccess(player: Player) {
        RandomSingleton.instance?.nextFloat()?.let {
            player.playSound(player.location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.4f, it)
        }
    }

    fun mendFail(player: Player) {
        player.playSound(player.location, Sound.ENTITY_ITEM_BREAK, 1f, .6f)
        player.sendMessage("You need more XP")
    }
}
